package lib.bone.admin.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lib.bone.admin.anno.WebLog;
import lib.bone.admin.constant.MethodTypeConst;
import lib.bone.common.core.domain.ResponseDTO;
import lib.bone.system.domain.dto.RoleMenuAddDTO;
import lib.bone.system.service.SysRoleMenuService;
import lib.bone.system.service.impl.SysRoleMenuServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system")
@Api(tags = "菜单授权管理")
public class SysRoleMenuController {
    @Autowired
    SysRoleMenuService sysRoleMenuService;
    /**
     * 为某角色新增对应页面
     */
    @WebLog(module = "bone-system")
    @PostMapping("role/menu")
    @ApiOperation(value = "新增角色菜单")
    @SaCheckPermission(value = "system_menu:add",orRole = "admin")
    public ResponseDTO addRoleMenu(@RequestBody @Validated RoleMenuAddDTO roleMenuAddDTO){
        /**
         * 写入
         */
        return sysRoleMenuService.addRoleMenu(roleMenuAddDTO.getRoleId(), roleMenuAddDTO.getMenuId());
    }
    /**
     * 查询某个角色对应的菜单
     */
    @GetMapping("roles/{roleId}/menus")
    @ApiOperation(value = "查询角色拥有的菜单",notes = "")
    @SaCheckPermission(value = "system_role:list",orRole = "admin")
    public ResponseDTO getRoleMenus(@PathVariable("roleId") Long roleId){
        return sysRoleMenuService.getRoleMenus(roleId);
    }

}
